import Vue from "vue";
import VueRouter from "vue-router";

//todo import命令表示同步加载
//todo import函数可以做异步加载
// import HotIndex from "../pages/hot/HotIndex";
// import CinemaIndex from "../pages/cinema/CinemaIndex";
// import WaitIndex from "../pages/wait/WaitIndex";
// import ClassicIndex from "../pages/classic/ClassicIndex";
// import DetailIndex from "../pages/detail/DetailIndex";
// import NotFound from "../pages/notFound/NotFound";

Vue.use(VueRouter);

// 创建路由表
const routes = [
  {
    //todo 重定向
    path: "/",
    redirect: "/hot",
  },
  {
    path: "/hot",
    component: () => import("../pages/hot/HotIndex"),
    //todo children属性用于做嵌套路由,表示子路由
    children: [
      {
        path: "/hot",
        redirect: "/hot/hot1",
      },
      {
        path: "hot1",
        // path: "/hot/hot1",
        component: () => import("../pages/hot/hot1/Hot1Index"),
      },
      {
        path: "hot2",
        component: () => import("../pages/hot/hot2/Hot2Index"),
      },
    ],
  },
  {
    path: "/cinema",
    //todo 路由别名
    alias: "/abc",
    //todo 命名路由
    name: "cinema",
    component: () => import("../pages/cinema/CinemaIndex"),
  },
  {
    path: "/wait",
    // component: () => import("../pages/wait/WaitIndex"),
    //todo 命名视图
    components: {
      a: () => import("../pages/wait/WaitIndex"),
      b: () => import("../pages/wait/Wait2Index"),
    },
  },
  {
    path: "/classic",
    component: () => import("../pages/classic/ClassicIndex"),
  },
  {
    //todo 动态路由
    path: "/detail/:id",
    name: "detail",
    props: true,
    component: () => import("../pages/detail/DetailIndex"),
  },
  {
    //todo 404页面一定要放在路由表的最后
    //todo vue的路由默认是排他性路由
    path: "*",
    component: () => import("../pages/notFound/NotFound"),
  },
];

// 创建路由实例
const router = new VueRouter({
  //todo 将路由设置成history模式
  // mode: "history",
  routes,
});

export default router;
